diff --git a/src/google/protobuf/compiler/python/generator.cc b/src/google/protobuf/compiler/python/generator.cc
index d8d6d7492..211fef038 100644
--- a/src/google/protobuf/compiler/python/generator.cc
+++ b/src/google/protobuf/compiler/python/generator.cc
@@ -252,6 +252,12 @@ bool Generator::Generate(const FileDescriptor* file,
     pure_python_workable_ = true;
   }
 
+  // This is pretty much the most egregious hack. GRPC and protobuf
+  // bazel rules can't agree on how to flatten the directory structure for protobufs
+  // in python. Periods are not actually allowed in names, but this seems to placate all
+  // the compilers and this file is not actually used.
+  filename = StringReplace(filename, "github/com/gogo", "github.com/gogo", false);
+
   FileDescriptorProto fdp;
   file_->CopyTo(&fdp);
   fdp.SerializeToString(&file_descriptor_serialized_);
